package com.campus.client.controller;


import com.campus.pojos.domain.ClientComment;
import com.campus.pojos.domain.dto.CommentDto;
import com.campus.pojos.domain.vo.CommentVo;
import com.campus.result.Result;
import com.campus.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/client/comment")
@Slf4j
/**
 * 评论相关接口
 */
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 查询帖子根评论
     * @param id
     * @return
     */
    @GetMapping("/getRoot/{id}")
    public Result<List<CommentVo>> getRoot(@PathVariable Integer id)
    {
        log.info("根据帖子id{}获取评论", id);
        return commentService.getRoot(id);
    }

    /**
     * 查询帖子评论
     * @param id
     * @return
     */
    @GetMapping("/getSon/{id}")
    public Result<List<CommentVo>> getSon(@PathVariable Integer id)
    {
        log.info("根据评论id为{}的子评论", id);
        return commentService.getSon(id);
    }

    /**
     * 删除帖子评论
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id)
    {
        commentService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加评论
     * @param commentDto
     * @return
     */
    @PostMapping("/save")
    public Result add(@RequestBody CommentDto commentDto)
    {
        commentService.add(commentDto);
        return Result.success();
    }



}
